
package Monopol.AssetGroups;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;

import Player.Player;
import Square.Service;


/**
 * @author Avia Tam
 * @author Assaf Miron
 *
 */
public class AllServices implements AssetGroup{
	ArrayList<Service>services; // All the Services in the Game

	/**
	 * Constructs the Services Group with a Clean Services Array 
	 */
	public AllServices() {
		super();
		this.services = new ArrayList<Service>(); // Allocate new Services Array List
		this.services.clear(); // Initialize the Services Array List
	}

	/**
	 * @return The Services Array
	 */
	public ArrayList<Service> getServices() {
		return services;
	}

	/**
	 * Add a Service to the Services Array
	 * @param service The Service to be Added
	 */
	public void addServices(Service service) {
		this.services.add(service);
	}
	
	/**
	 * Creates a New Transportation Object and Adds it to the Transportation Group
	 * @param transName The Transportation Name
	 * @param stayPrice The Stay Price Array
	 * @param cost The Transportation Cost
	 * @return a Transportation Object
	 */
	public Service createService(String svcName, Double[] stayPrice, Double cost)
	{
		// Create a New Service
		Service service = new Service(svcName, stayPrice, cost, this);
		// Add this Service to the Service Group
		this.addServices(service);
		// Return the Newly Created Service
		return service;
		
	}

	/* (non-Javadoc)
	 * @see Monopol.AssetGroup#isAllAssetGroupMine(Player.Player)
	 */
	@Override
	public Boolean isAllAssetGroupMine(Player player) 
	{
		// Create an Iterator to run on the Assets Group
		Iterator<Service> i = services.iterator();		 
		// Create a Temporary boolean variable - Check if all the group is owned by the same Player
		Boolean allGroups = new Boolean(true);
		// Loop the State while all the Cities have the same Owner
		while(i.hasNext() && allGroups)
		{
			// Check the Owner and compare with the Player
			if(i.next().getOwner() != player)
			{
				// Not the Same Owner as Player - Stop Checking
				allGroups = false;
			}
		}
		// Return the Value of All Groups
		return allGroups;
	}

	/* (non-Javadoc)
	 * @see Monopol.AssetGroup#getName()
	 */
	@Override
	public String getName() 
	{
		return "All Services";
	}

	/* (non-Javadoc)
	 * @see Monopol.AssetGroup#getAssets()
	 */
	@Override
	public ArrayList<?> getAssets() 
	{
		return services;
	}

	/* (non-Javadoc)
	 * @see Monopol.AssetGroups.AssetGroup#getColor()
	 */
	@Override
	public Color getColor() {
		// All Services are Purple-Blue-ish
		return new Color( 186, 163, 248 );
	}
	
}
